package com.woniuxy.house.mapper;

import com.woniuxy.house.entity.Message;
import com.woniuxy.house.entity.Report;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 针对举报信息的mapper接口
 */
public interface ReportMapper {
    /**
     *增加举报消息
     * @param report
     */
    @Insert("insert into house_report(conent,time,isacross,user_id,opp_user_id)values(#{conent},#{time},#{isacross},#{reported.id},#{report.id})")
    void add(Report report);

    /**
     * 删除举报信息(根据id)
     * @param id
     */
    @Delete("delete from house_report where id=#{id} ")
    void delete(Integer id);

    /**
     * 根据用户id 删除举报消息 （这里也有可能是多条消息）
     * @param id
     */
    @Delete("delete from house_report where user_id=#{id}")
    void deleteByUser(Integer id);

    /**
     * 根据用户id查询消息(举报者,被举报者)
     * @param id
     * @return  report 类型的list集合
     */
    @Select("select * from house_report where user_id=#{id}")
    List<Report> getByUserId(Integer id);

    /**
     * 根据id查询消息
     * @param id
     * @return report 实体类（并带出用户信息,一个举报者 一个被举报者）
     */
    @Select("select m.* from house_message m, house_user u where m.user_id=u.id and m.id=#{id}")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "conent",property = "content"),
            @Result(column = "time",property = "time"),
            @Result(column = "user_id",property = "reported",one = @One(select="com.woniuxy.house.mapper.UserMapper.getById",fetchType = FetchType.LAZY)),
            @Result(column = "opp_user_id",property = "report",one = @One(select="com.woniuxy.house.mapper.UserMapper.getById",fetchType = FetchType.LAZY)),

    })
    Report getById(Integer id);


}
